﻿using System;
using Xunit;

namespace TestXunit
{
    public sealed class TestException
    {
        private static int SimpleMath(int x, int y)
        {
            if (y == 0)
            {
                throw new DivideByZeroException("cannot divided by zero");
            }
            return x / y;
        }

        [Fact]
        public void Demo()
        {
            var ex = Assert.Throws<DivideByZeroException>(() => SimpleMath(1, 0));
            // note: below tests failed, because 'If the code throws any other exception, 
            // even one that's derived from the one you're expecting, it's still a failure.'
            // Assert.Throws<Exception>(() => SimpleMath(1, 0));

            Assert.Equal("cannot divided by zero", ex.Message);
        }
    }
}
